package com.itheima.tliasmanagement.filter;


import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

@Slf4j
//@WebFilter(urlPatterns = "/*")
public class DemoFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        log.info(((HttpServletRequest)request).getRequestURI());
        log.info("DemoFilter 放行前逻辑");
        // 继续向下执行，可能是执行到servlet中，也可能是执行下一个filter
        chain.doFilter(request, response);
        log.info("DemoFilter 放行后逻辑");
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
       // 初始化的时候，仅仅执行一次
        log.info("DemoFilter init");
    }

    @Override
    public void destroy() {
        // 销毁的时候，仅仅执行一次
        log.info("DemoFilter destroy");
    }
}
